package banding.com.google.Zxing.utils;

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.util.Log;
import android.widget.Toast;

import banding.com.google.Zxing.camera.CameraManager;

public class FlashlambUtil {
	// 检测当前设备是否配置闪光灯
	public static boolean checkFlashlight(Context context) {
		if (!context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH)) {
			Toast.makeText(context, "当前设备没有闪光灯", Toast.LENGTH_LONG).show();
			return false;
		}
		return true;
	}

	// 打开闪光灯
	public static void openFlashlight() {

		try {
			Camera mCamera = CameraManager.get().getCamera();
			if (mCamera!=null) {
				
			Parameters mParameters = mCamera.getParameters();
			mParameters.setFlashMode(Parameters.FLASH_MODE_TORCH);
			mCamera.setParameters(mParameters);
			}
			mCamera=null;
		} catch (Exception e) {
			Log.e(FlashlambUtil.class.getSimpleName(), "闪光灯"+e);
		}
	}

	// 关闭闪光灯
	public static void closeFlashlight() {
		Camera mCamera = CameraManager.get().getCamera();
		if (mCamera != null) {
			Parameters mParameters = mCamera.getParameters();
			mParameters.setFlashMode(Parameters.FLASH_MODE_OFF);
			mCamera.setParameters(mParameters);
			mCamera = null;
		}
	}
}
